Conversation
…ak fix and minor cleanups
…_state_changed signature and state property fixes; add memory leak prevention in controller dispose; add thread-safety to EventBus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses several critical bugs and memory leaks in the FletX framework, adds thread-safety to core components, and introduces test coverage for previously untested modules (services, effects, factory). The changes improve stability, prevent crashes, and ensure proper resource cleanup.
Changes
Bug Fixes (High Priority)
Controller Event Loop Typo (
fletx/core/controller.py:165)get_event_loop.create_task→get_event_loop().create_taskto preventAttributeErrorwhen emitting async events viaEventBus.once().Controller State Comparison (
fletx/core/controller.py:419)self._state != ControllerState.INITIALIZED→self._state.value !=to correctly compare the reactive state's value with the enum, enabling controllers to reach theREADYstate.Service State Listener Signature (
fletx/core/services.py:158-161)on_state_changed(self, state: ServiceState)→on_state_changed(self)to match the listener callback (which passes 0 arguments), preventingTypeErrorwhen state changes occur.Computed Property Observer Leak (
fletx/core/state.py)_dep_observerslist to track dependency observers inComputed._update_value()to properly dispose of old observers before creating new ones.dispose()to clean up dependency observers.DI Container Memory Leak (
fletx/core/controller.py:448-451)DI.delete()calls inFletXController.dispose()to remove controller and effect manager instances from the DI container, preventing memory leaks.EventBus Thread-Safety (
fletx/core/controller.py)threading.RLocktoEventBusto protect concurrent access to_listeners,_once_listeners,_event_history, and_last_eventduringemit()andoff()operations.emit()andoff()withwith self._lock.CLI String Formatting (
fletx/cli/commands/newproject.py:204-206)"\{'='*50}\"→"=" * 50to correctly display separators in project creation output.New Test Coverage (Medium Priority)
Added comprehensive unit tests for:
tests/test_services.py): Service state transitions, data handling, disposal, and error management.tests/test_effects.py): Effect registration, dependency tracking, cleanup behavior, and conditional execution.tests/test_factory.py): Widget registration, duplicate prevention, method validation, andregister_allfunctionality.Impact
All existing tests continue to pass, and the new tests validate the fixed behaviors.
Checklist